var mongoose = require("mongoose");
let url = "mongodb://admin:lyc_admin@39.105.197.66:27017/Muscleman?authSource=admin";

mongoose.connect(url, (err) => {
  if (!err) {
    console.log("连接成功,运行端口:3461");
  }
});

const Schema = mongoose.Schema;

/** 管理员列表*/
const AdminSchema = new Schema({
  username: String,
  pwd: String,
  roles: String,
  photo: String, // 人脸图片
});

const AdminModel = mongoose.model("admin", AdminSchema);

/** 会员管理*/
const UserSchema = new Schema({
  username: String,
  // place: { type:  Boolean, default: true } /** 身份類型*/,
  phone: String,
  pwd: String,
  createTime: {
    type: Date,
    default: Date.now,
  },
  recentlylogged: { type: Date, default: "" } /** 最近登陆时间*/,
  state: { type: Boolean, default: true } /** 0 正常 1 已锁定*/,
});
const GrSchema = new Schema({
  username: String,
  // place: { type:  Boolean, default: true } /** 身份類型*/,
  phone: String,
  pwd: String,
  createTime: {
    type: Date,
    default: Date.now,
  },
  recentlylogged: { type: Date, default: "" } /** 最近登陆时间*/,
  state: { type: Boolean, default: true } /** 0 正常 1 已锁定*/,
});
const UserModel = mongoose.model("user", UserSchema);
const GrModel = mongoose.model("gr", GrSchema);

/** 簡歷管理*/
const resumeSchema = new Schema({
  head: String /** 头像*/,
  name: String,
  sex: { type: String, default: "1" },
  birthday: Date,
  education: String /**学历*/,
  enterWork: Date /** 参加工作时间*/,
  jobstatus: String /** 求职状态*/,
  maritalstatus: String /** 婚姻状况*/,
  currentresidence: String /** 现居住地*/,
  major: { type: String, default: "" } /** 所学专业*/,
  height: { type: String, default: "" },
  nativeplace: { type: String, default: "" } /** 籍贯*/,
  IDnumber: { type: String, default: "" },
  naturework: { type: String, default: "" } /** 工作性質*/,
  intendedposition: String /** 意向職位*/,
  workarea: String /** 工作地區*/,
  salaryexpectation: String /** 期望薪資*/,
  expectedindustry: { type: String, default: "" } /** 期望行業*/,
  phone: String,
  wx: String,
  email: { type: String, default: "" },
  QQ: { type: String, default: "" },
});

const ResumeModel = mongoose.model("resume", resumeSchema);

/** 廣告管理*/
const advertisementSchema = new Schema({
  title: String,
  cname: String /** 所属广告位 */,
  platform: String, /** 所属平台 */
  imageUrl: String,
  starttime: Date,
  deadline: Date,
  sort_id: Number,
  targetUrl: String /** 目标地址*/,
  custom: String /** 自定义跳转链接*/,
  is_display: String /** 是否显示 0 显示 1 不显示*/,
});

const AdvertisementModel = mongoose.model("advertisement", advertisementSchema);

/** 广告位管理*/
const advertisingspaceSchema = new Schema({
  platform: String /**  所属平台*/,
  name: String,
  call: String /** 调用*/,
  number: String,
  width: String,
  height: String,
  is_sys: String,
});

const AvertisingspaceModel = mongoose.model(
  "advertisingspace",
  advertisingspaceSchema
);

/** 线索管理*/
const clueSchema = new Schema({
  ThreadName: String, // 线索名称
  TheirMarket: { type: mongoose.Types.ObjectId, default: null }, // 所属销售
  Linkman: { type: String, default: "" }, // 联系人
  phone: { type: String, default: "" }, // 联系电话
  RelationWeChat: { type: String, default: "" }, // 联系微信
  Customer: { type: String, default: "" }, // 客户行业
  PlaceArea: { type: Array, default: [] }, // 所在地区
  Detailed: { type: String, default: "" }, // 详细地址
  TurnoverTime: { type: Date, default: () => new Date(), set: () => new Date() }, // 更新时间
  createTime: { type: Date, default: () => new Date() }, // 创建时间
  FollowUp: { type: Number, default: 0 }, // 跟进次数
  Creator: { type: mongoose.Types.ObjectId },  // 创建人关联id
  CompanySpecification: { type: String, default: "" }, // 公司规模
  Remark: { type: String, default: "" }, // 备注
});

const ClueModel = mongoose.model("clue", clueSchema);

const positionCateSchema = new Schema({
  classification: String /** 所属分类*/,
  name: String,
  paixu: String,
  p_id: Number,
  name: String,
  value: String,
});

const PositionModel = mongoose.model("position", positionCateSchema);
// 客户
const customerSchema = new Schema({
  username: String, // 用户名
  password: String, // 密码
  logo: String, // logo图片
  enterpriseName: String, // 企业名称
  enterpriseNature: String, // 企业性质
  enterpriseShort: String, // 企业名称
  industryInvolved: { type: Schema.Types.ObjectId, default: "" }, // 所属行业
  location: String, // 所在地区
  bindingWechat: String, // 绑定微信
  CompanySpecification: String, // 公司规格
  registeredFund: String, // 注册资金
  relationTelephone: String, // 联系固话
  relationEmail: String, // 联系邮箱
  relationQQ: String, // 联系QQ
  presentIntegral: String, // 赠送积分
  chargeAmount: String, // 收费金额
  companyURL: String, // 公司网址
  companyBrief: String, // 公司简介
  companyIntroduce: String, // 公司介绍
  enterpriseWelfare: String, // 企业福利,
  ContactAddress: String,// 联系地址
  clientGrade: String, // 客户等级
  contacts: String, // 联系人
  enterpriseContactWay: String, // 企业联系方式
  memberContactWay: String, // 会员联系方式 | 添加页面手机号
  position: String, // 在招职位
  receiptNotification: String, // 收到简历
  enterpriseSetmeal: String, // 企业套餐
  setmealResidue: String, // 套装剩余
  refreshTime: String, // 刷新时间
  registrationTime: { type: Date, default: Date.now }, // 注册时间
  loginTime: { type: Date, default: Date.now }, // 登陆时间
  involvedMarket: { type: Schema.Types.ObjectId, default: "" }, // 所属销售
  authenticationStatus: String, // 认证状态
  displayStatus: String, // 显示状态
  finallyFollowup: String, // 最后跟进
  notFollowup: String, // 未跟进
});
const CustomerModel = mongoose.model("customer", customerSchema);

// 线索跟进记录
const clueHistory = new Schema({
  clue: mongoose.Types.ObjectId, // 对应线索
  sale: mongoose.Types.ObjectId, // 所属销售
  contacts: String, // 联系人
  type: String, // 跟进方式
  createTime: { type: Date, default: Date.now }, // 创建时间
  result: String, // 跟进结果
  image: { type: Array, default: [] } // 图片
})
const clueHistoryModel = mongoose.model('cluehistory', clueHistory)

module.exports = {
  AdminModel,
  UserModel,
  GrModel,
  ResumeModel,
  AdvertisementModel,
  AvertisingspaceModel,
  ClueModel,
  PositionModel,
  CustomerModel,
  clueHistoryModel,
};
